import org.apache.ibatis.ognl.DefaultMemberAccess;
import org.apache.ibatis.ognl.Ognl;
import org.apache.ibatis.ognl.OgnlContext;
import org.apache.ibatis.ognl.OgnlException;

import java.util.HashMap;
import java.util.Map;

public class OgnlExample {
    public static void main(String[] args) {
        String expression = "schoolId!=''";
        try {
            Object parsedExpression = Ognl.parseExpression(expression);
            // 创建一个 Map 用于存储上下文数据
            Map<String, Object> contextMap = new HashMap<>();
            contextMap.put("schoolId", 0L);

            // 创建 DefaultMemberAccess 实例
            DefaultMemberAccess memberAccess = new DefaultMemberAccess(true);

            // 使用带参数的构造函数创建 OgnlContext 对象
            OgnlContext context = new OgnlContext(null, null, memberAccess, contextMap);

            Object result = Ognl.getValue(parsedExpression, context, context.getRoot());
            System.out.println("判断结果: " + result);
        } catch (OgnlException e) {
            e.printStackTrace();
        }
    }
}